$(document).ready(function () {
    // banner
    var swiper = new Swiper('#town-banner', {
        spaceBetween: 0,
        centeredSlides: true,
        keyboard: {
            enabled: true,
        },
        /*autoplay: {
          delay: 2500,
          disableOnInteraction: false,
        },*/
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        }
    });
    /*头部导航*/
    $("#head-nav7").children(".drop-nav").show();
    $("#head-nav7_1").addClass("active");
    var townTabsSwiper = new Swiper('#b-town-tabs', {
        freeMode: true,
        slidesPerView: 'auto',
        freeModeSticky: true,
    });
    var townSetSwiper = new Swiper('#b-town-set', {
        speed: 500,
        on: {
            slideChangeTransitionStart: function () {
                $(".policy-tabs .active").removeClass('active');
                $(".policy-tabs a").eq(this.activeIndex).addClass('active');
            }
        }
    });
    $(".policy-tabs a").on('click', function (e) {
        e.preventDefault()
        $(".policy-tabs .active").removeClass('active')
        $(this).addClass('active')
        townSetSwiper.slideTo($(this).index());
    });

    var townOnlineSwiper = new Swiper('#town-online', {
        freeMode: true,
        slidesPerView: 'auto',
        freeModeSticky: true,
    });
    var townUnlineSwiper = new Swiper('#town-unline', {
        freeMode: true,
        slidesPerView: 'auto',
        freeModeSticky: true,
    });
    /*师资介绍*/
    var townTeacherSwiper = new Swiper('#town-teacher', {
        freeMode: true,
        slidesPerView: 'auto',
        freeModeSticky: true,
    });

    $(".b-town-tea a").on('click', function (e) {
        e.preventDefault();
        var index = $(this).index();
        $(".b-town-tea .active").removeClass('active');
        $(this).addClass('active');
        $(".teacher-info .teacher-info-item").eq(index).addClass("show").siblings(".teacher-info-item").removeClass("show");
    });
    var townDynamicSwiper = new Swiper('#town-dynamic', {
        freeMode: true,
        slidesPerView: 'auto',
        freeModeSticky: true,
    });

    /*抢座跳转*/
    $(".signUp").click(function () {
        var target = $(this.hash);
        $("body,html").animate({
            'scrollTop': target.offset().top - 100
        }, 1000);
    });

    /*视频弹框*/
    $(".b-town-online li a").click(function () {
        $(".b-town-video-tk,.tk-bg").fadeIn(300);
        $('body').css("overflow","hidden");
        var myPlayer = videojs('my-video');
        var videoUrl = $(this).attr("videohref");
        var videoTitle = $(this).children(".con").children("p").text();
        $(".b-town-video-title .video-title").text(videoTitle);

        videojs("my-video", {}, function () {
            window.myPlayer = this;
            /*$(".app-video-tk #my-video source").attr("src", videoUrl);*/
            myPlayer.src(videoUrl);
            myPlayer.load(videoUrl);
            myPlayer.play();
        });
        $(".click-modal").click();
    });
    $('.b-town-video-tk').on('hidden.bs.modal', function () {
        myPlayer.pause();
    });

    $(".tk-bg,.video-close").click(function () {
        $(".b-town-video-tk,.tk-bg").fadeOut(300);
        $('body').css("overflow","auto");
        myPlayer.pause();
    });

    /*图片点击放大效果*/
    /*精彩动态图片点击放大效果*/
    $(".town-dynamic li").click(function () {
        $("#tk-slide,.tk-bg").fadeIn(300);
        $('body').css("overflow", "hidden");
        var memeryImageSetId = $(this).children('img').data('setid');
        $.ajax({
            url: "/albumPhotos",
            data: {
                subType: memeryImageSetId,
                photoType: 1
            },
            type: "get",
            success: function (res) {
                var images = JSON.parse(res).data;
                var html = '<section id="section-header" data-coloroverlap="dark"></section>\
                            <div id="character-slider" class="sky-carousel sc-no-select">\
                                <div class="close-btn"></div>\
                                <div class="sky-carousel-wrapper">\
                                    <ul class="sky-carousel-container" id="memeryImgSet">\
                                    </ul>\
                                </div>\
                            </div>';
                $('#tk-slide').append(html);

                for (img in images) {
                    var imgHtml = '<li><img src="' + images[img].url + '" class="sc-image"></li>';
                    $('#memeryImgSet').append(imgHtml);
                }
                /*图片旋转木马特效*/
                buildSideNav();
                skyCarousel = $('#character-slider').carousel({
                    itemWidth: 310,
                    itemHeight: 220,
                    enableMouseWheel: false,
                    gradientOverlayVisible: true,
                    gradientOverlayColor: '#F0F3EE',
                    gradientOverlaySize: 200,
                    distance: 10,
                    selectedItemDistance: 10,
                    selectByClick: true,
                    selectedItemZoomFactor: 0.8,
                    unselectedItemZoomFactor: 0.8,
                    navigationButtonsVisible: false,
                    showPreloader: false,
                    autoSlideshow: false
                });

                $(".tk-bg,.close-btn").click(function () {
                    $('#tk-slide').empty();
                    $(".tk-bg, #tk-slide").fadeOut(300);
                    $('body').css("overflow", "auto");
                    return;
                });
            }
        });
    });
    $(".tk-bg,.close-btn").click(function () {
        $(".tk-bg, #tk-slide").fadeOut(300);
        return;
    });

    /*动态获取参训企业数据*/
    $.ajax({
        type: 'get',
        url: '/customers',
        data: {
            classType: 'town',
        },
        success: function(res){
            res = JSON.parse(res);
            resData = res.data;
            $.each(resData, function(i, item){
                var listItem = '<li>\
                                    <span class="w1">' + item.company_name + '</span>\
                                    <span class="w2">' + item.custom_name + '</span>\
                                </li>';
                $("#custom-list").append(listItem);
            });
        }
    });
});
